<template>
<div class="bg-white">
    <div class="bg-toolbar">
        <DatePicker :value="value2" format="yyyy/MM/dd" type="daterange" placement="bottom-end" placeholder="Select date" style="width: 200px"></DatePicker>
        &nbsp;&nbsp;&nbsp;
        <Button type="primary" icon="ios-search">搜索</Button>

    </div>
    <Card shadow :bordered="false">
        <div ref="dom2" :style="`height:${height1}px;`"></div>
    </Card>
</div>

</template>

<script>
import echarts from 'echarts'
import { getNowDate, formatDate } from '../../libs/tools'
export default {
  data () {
    return {
      height1: 500,
      dom2: null,
      value2: [getNowDate(), getNowDate()]
    }
  },
  methods: {
    resize () {
      this.dom2.resize()
    },
    getData (d1, d2) {
      const xData = []
      for (let i = 0; i < 24; i++) {
        xData.push(i)
      }
      const option = {
        legend: {},
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        grid: {
          top: '10%',
          left: '1.2%',
          right: '1%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            axisLabel: {
              // inside: true,
              textStyle: {
                // color: '#fff'
              }
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: false
            },
            z: 10,
            data: xData
          }
        ],
        dataZoom: [
          {
            type: 'inside'
          }
        ],
        yAxis: [
          {
            type: 'value',
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              textStyle: {
                color: '#999'
              }
            }
          }
        ],
        series: [
          {
            type: 'bar',
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0, 0, 0, 1,
                  [
                    { offset: 0, color: '#83bff6' },
                    { offset: 0.5, color: '#188df0' },
                    { offset: 1, color: '#188df0' }
                  ]
                )
              },
              emphasis: {
                color: new echarts.graphic.LinearGradient(
                  0, 0, 0, 1,
                  [
                    { offset: 0, color: '#2378f7' },
                    { offset: 0.7, color: '#2378f7' },
                    { offset: 1, color: '#83bff6' }
                  ]
                )
              }
            },
            stack: '总量',
            areaStyle: { normal: {
              color: '#BAD9FF'
            } },
            data: d2
          }

        ]
      }
      return option
    },
    switchDataType (type) {
      const dataMap = [
        [
          [27, 358, 278, 234, 290, 330, 310, 290, 130, 310, 290, 330, 310, 100, 90, 290, 330, 310, 1, 290, 330, 310, 100, 100],
          [120, 132, 101, 134, 90, 230, 210, 100, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210, 90, 230, 210]
        ],
        [
          [157, 358, 278, 234, 290, 330, 310, 290, 330, 310, 290, 330, 310, 100, 90, 290, 330, 310, 1, 290, 330, 310, 100, 110],
          [120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210, 90, 230, 210]
        ]
      ]
      this.dom2.setOption(this.getData(...dataMap[type]))
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.dom2 = echarts.init(this.$refs.dom2)
      this.dom2.setOption(this.getData(
        [257, 358, 278, 234, 290, 330, 310, 290, 330, 310, 290, 330, 310, 100, 90, 290, 330, 310, 1, 290, 330, 310, 100, 100],
        [120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210, 90, 230, 210]
      ))
    })
    // this.height1 = window.innerHeight - 250
  },

  beforeDestroy () {
  }
}
</script>
<style>
.bg-white{
 background: #fff;
 padding:30px;
}
.bg-toolbar{
    padding-bottom: 30px;
}
</style>
